﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.effects {
    import flash.geom.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Engine.*;

    public class ArcMotion {

        protected const DOOBER_DROP_SPEED_FACTOR:Number = 1;

        protected var m_gameObject:GameObject;
        protected var m_endPosition:Point;
        protected var m_startPosition:Point;
        protected var m_startVelocity:Point;
        protected var m_gravity:Number;
        protected var m_velocity:Point;
        protected var m_complete:Boolean;
        protected var m_newPosX:Number;
        protected var m_newPosY:Number;

        public function ArcMotion(_arg1:GameObject, _arg2:Point, _arg3:Point, _arg4:Number, _arg5:Number){
            this.m_gameObject = _arg1;
            this.m_startPosition = _arg2;
            this.m_endPosition = _arg3;
            this.m_startVelocity = new Point(0, _arg4);
            this.m_gravity = _arg5;
            this.init();
        }
        public function init():void{
            var _local1:Point = IsoMath.viewportToStage(IsoMath.tilePosToPixelPos(this.m_startPosition.x, this.m_startPosition.y));
            var _local2:Point = IsoMath.viewportToStage(IsoMath.tilePosToPixelPos(this.m_endPosition.x, this.m_endPosition.y));
            var _local3:Number = (_local2.y - _local1.y);
            var _local4:Number = this.m_startVelocity.y;
            var _local5:Number = ((-(_local4) + Math.sqrt((Math.pow(_local4, 2) - (((4 * 0.5) * this.m_gravity) * -(_local3))))) / ((2 * 0.5) * this.m_gravity));
            var _local6:Number = ((_local2.x - _local1.x) / _local5);
            this.m_startVelocity.x = _local6;
            this.m_velocity = this.m_startVelocity;
            this.m_complete = false;
        }
        public function update(_arg1:Number):void{
            var _local2:Number;
            var _local3:Vector3;
            var _local4:Point;
            var _local5:int;
            var _local6:Number;
            var _local7:Point;
            var _local8:Point;
            if (!this.m_complete){
                _local2 = (_arg1 * 33);
                _local2 = (_local2 * this.DOOBER_DROP_SPEED_FACTOR);
                if (_local2 < 1){
                    _local2 = 1;
                };
                _local3 = this.m_gameObject.getPosition();
                _local4 = IsoMath.viewportToStage(IsoMath.tilePosToPixelPos(this.m_endPosition.x, this.m_endPosition.y));
                _local5 = 0;
                while (_local5 < _local2) {
                    _local6 = (_local2 - _local5);
                    if (_local6 > 1){
                        _local6 = 1;
                    };
                    this.m_velocity.y = (this.m_velocity.y + (this.m_gravity * _local6));
                    _local7 = IsoMath.viewportToStage(IsoMath.tilePosToPixelPos(_local3.x, _local3.y));
                    this.m_newPosX = (_local7.x + (this.m_velocity.x * _local6));
                    this.m_newPosY = (_local7.y + (this.m_velocity.y * _local6));
                    _local8 = IsoMath.screenPosToTilePos(this.m_newPosX, this.m_newPosY);
                    _local3.x = _local8.x;
                    _local3.y = _local8.y;
                    if (this.m_newPosY >= _local4.y){
                        break;
                    };
                    _local5++;
                };
                this.m_gameObject.setPosition(_local8.x, _local8.y);
                this.m_gameObject.conditionallyReattach();
                this.checkComplete();
            };
        }
        public function checkComplete():void{
            var _local1:Point = IsoMath.viewportToStage(IsoMath.tilePosToPixelPos(this.m_endPosition.x, this.m_endPosition.y));
            if (this.m_newPosY >= _local1.y){
                this.onComplete();
            };
        }
        public function onComplete():void{
            this.m_complete = true;
        }
        public function get isComplete():Boolean{
            return (this.m_complete);
        }

    }
}//package Classes.effects 
